package itheima03;
/*
    递归求阶乘
    4的阶乘 = 4 * 3 * 2 * 1

    假设定义求n的阶乘的方法: jieCheng(int n)

    求 n 的阶乘?

    求 4 的阶乘

    jieCheng(4) = 4 * 3 * 2 * 1
        = 4 * jieCheng(3)
            jieCheng(3) = 3 * 2 * 1
                = 3 * jieCheng(2)
                    jieCheng(2) = 2 * 1
                        = 2 * jieCheng(1)
                        jieCheng(1) = 1
    总结:
        1.规律
           jieCheng(4) =  4 * jieCheng(4 - 1)
           jieCheng(n) = n * jieCheng(n-1)
        2.出口
          jieCheng(1) = 1
          if(n==1){
            return 1;
          }

 */
public class Demo03JieCheng {
    public static void main(String[] args) {
        //调用方法
        int result = jieCheng(100);
        System.out.println(result);
    }
    //定义求阶乘的方法: 递归调用
    public static int jieCheng(int n) {
        //2.出口
        if(n==1) {
            return 1;
        }
        //1.规律
        return n * jieCheng(n-1);
    }
}
